package com.ytjj.qmyx.admin.eunm;


import com.ytjj.qmyx.admin.model.response.DynamicCategoryResp;

import java.util.ArrayList;
import java.util.List;

public enum DynamicCategoryEnums {

    MAIN_PAGE_QUALITY(0,"优质测评"),
    MAIN_PAGE_ELECTRIC(1,"智家"),
    MAIN_PAGE_GETFIT(3,"美妆"),
    MAIN_PAGE_LIFE(4,"美食"),
    MAIN_PAGE_GALLEY(2,"居家"),
    MAIN_PAGE_HEALTH(7,"养生"),
    MAIN_PAGE_ACC(8,"潮搭"),
    ;
    ;


    private Integer code;

    private String name;

    DynamicCategoryEnums(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据枚举code获取名称
     * @param code
     * @return
     */
    public static String getNameByCode(Integer code){
        DynamicCategoryEnums[] list = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums item : list) {
            if (item.getCode().equals(code)) {
                return item.getName();
            }
        }
        return null;
    }

    /**
     * 根据枚举name获取code
     * @param name
     * @return
     */
    public static Integer getCodeByName(String name) {
        DynamicCategoryEnums[] values = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums value : values) {
            if(value.name.equals(name)) {
                return value.getCode();
            }
        }
        return null;
    }

    public static List<DynamicCategoryResp> getTypeList() {
        List<DynamicCategoryResp> list = new ArrayList<>();
        DynamicCategoryEnums[] typeList = DynamicCategoryEnums.values();
        for (DynamicCategoryEnums type : typeList) {
            DynamicCategoryResp atp = new DynamicCategoryResp();
            atp.setCode(type.getCode());
            atp.setName(getNameByCode(type.getCode()));
            list.add(atp);
        }
        return list;
    }
}
